home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*----------------------------------------------------------------------------
- *
- * otext.c : openGL (motif) demo to draw bitmapped fonts using display lists
- *
- * Author : Yusuf Attarwala
- * SGI - Applications
- *
- * Date : Feb 93
- *
- *---------------------------------------------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
-
- #include <Xm/Xm.h>
- #include <Xm/Frame.h> /* for frame widgets */
-
- #include <GL/gl.h> /* gl includes */
- #include <GL/glu.h> /* utility library includes */
- #include <GL/GLwMDrawA.h> /* include for the drawing area widget */
-
- /* function declarations */
-
- int
- main(int,char **);
- static void
- createToplevel(void),
- drawScene(void),
- setMatrix(void),
- exposeCB(Widget, XtPointer, XtPointer),
- resizeCB(Widget, XtPointer, XtPointer),
- initCB(Widget, XtPointer, XtPointer);
-
- void makeFontSet(void),
- myCharStr(char *);
-
-
- /* global variables */
-
- Display *display; /* current display */
- XtAppContext appContext; /* X application context */
- GLuint base;
-
- Widget toplevel, /* toplevel shell */
- glw; /* current widget */
-
- GLXContext glxc; /* current glx context */
-
- char outputText[125];
- static GLfloat yellow[3] = {1.0,1.0,0.0};
-
- Arg args[20];
- int acnt;
-
- int
- main(int argc, char** argv)
- {
- int i;
- char oneWord[60];
-
- /* parse arguments, etc */
- if (argc > 1) {
- outputText[0] = '\0';
- for (i=1;i<argc;i++) {
- sprintf(oneWord,"%s ",argv[i]);
- strcat(outputText,oneWord);
- }
- }
- else {
- fprintf(stderr,"Usage : %s string1 [string2...]\n",argv[0]);
- strcpy(outputText,"HELLO WORLD");
- }
-
- XtToolkitInitialize();
- appContext = XtCreateApplicationContext();
- display = XtOpenDisplay(appContext, NULL, "Otext","otext",NULL,0,
- &argc,argv);
- if (!display) {
- printf("%s : Unable to open display\n",argv[0]);
- exit(0);
- }
- createToplevel(); /* create and realize widget hierarchy */
- XtAppMainLoop(appContext); /* loop for ever */
- }
-
-
-
- void
- createToplevel(void)
- {
- Widget frame;
-
- acnt = 0;
- XtSetArg(args[acnt],XmNminHeight, 200);acnt++;
- XtSetArg(args[acnt],XmNminWidth, 300);acnt++;
- toplevel = XtAppCreateShell("openGL text","xtext",
- applicationShellWidgetClass,
- display,args,acnt);
-
- /* create a frame to hold the glx drawing area */
- frame = XtVaCreateManagedWidget("frame",
- xmFrameWidgetClass, toplevel,
- NULL);
-
- /* create and manage a single buffer widget, rgb mode */
- acnt = 0;
- XtSetArg(args[acnt], GLwNrgba, TRUE); acnt++;
- glw = GLwCreateMDrawingArea(frame, "glw", args, acnt);
- XtManageChild(glw);
-
- /* register callbacks */
- XtAddCallback(glw, GLwNginitCallback, initCB, NULL);
-
- /* realize widget hierarchy */
- XtRealizeWidget(toplevel);
-
- /* generate display lists for text bitmaps */
- makeFontSet();
-
- /* additional callbacks */
- XtAddCallback(glw, GLwNresizeCallback, resizeCB, NULL);
- XtAddCallback(glw, GLwNexposeCallback, exposeCB, NULL);
-
- }
-
- void
- drawScene(void)
- {
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- glColor3fv(yellow);
- glRasterPos2i(10,10);
- myCharStr(outputText);
- glFlush();
- }
-
- static void
- setMatrix(void)
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0,100.0,0.0,100.0,-1.0,1.0); /* a simple ortho */
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity(); /* default view */
- }
-
- static void
- resizeCB(Widget w, XtPointer client_data, XtPointer call)
- {
- GLwDrawingAreaCallbackStruct *call_data;
- call_data = (GLwDrawingAreaCallbackStruct *) call;
-
- GLwDrawingAreaMakeCurrent(w, glxc);
- glViewport(0, 0, call_data->width, call_data->height);
- setMatrix();
- drawScene();
- }
-
- static void
- exposeCB(Widget w, XtPointer client_data, XtPointer call)
- {
- GLwDrawingAreaCallbackStruct *call_data;
- call_data = (GLwDrawingAreaCallbackStruct *) call;
-
- GLwDrawingAreaMakeCurrent(w, glxc);
- drawScene();
- }
-
- static void
- initCB(Widget w, XtPointer client_data, XtPointer call)
- {
- XVisualInfo *vi;
-
- XtSetArg(args[0], GLwNvisualInfo, &vi);
- XtGetValues(w, args, 1);
-
- glxc = glXCreateContext(XtDisplay(w), vi, 0, GL_TRUE);
- }
-
- void
- makeFontSet()
- {
- XFontStruct *xfont;
- unsigned int firstChar, lastChar;
-
- GLwDrawingAreaMakeCurrent(glw, glxc);
-
- xfont = XLoadQueryFont(display,"9x15");
- /* replace 9x15 with your favorite font set */
-
- if (!xfont) {
- fprintf(stderr,"FONT NOT FOUND \n");
- exit(0);
- }
-
- firstChar = xfont->min_char_or_byte2;
- lastChar = xfont->max_char_or_byte2;
-
- if (base = glGenLists(lastChar-firstChar+1)) {
- glXUseXFont(xfont->fid,firstChar,lastChar-firstChar+1,base+firstChar);
- }
- else {
- fprintf(stderr,"OUT OF DISPLAY LISTS\n");
- exit(0);
- }
- }
-
- void
- myCharStr(char *s)
- {
- glPushAttrib(GL_LIST_BIT);
- glListBase(base);
- glCallLists(strlen(s),GL_UNSIGNED_BYTE,(unsigned char *)s);
- glPopAttrib();
- }
-
-